Skip to content

add a workaround for getFunctions in Thrift#979

Merged
samikshya-db merged 8 commits into
databricks:mainfrom
samikshya-db:samikshya-chand_data/getFunctions
Sep 11, 2025
Merged

add a workaround for getFunctions in Thrift#979
samikshya-db merged 8 commits into
databricks:mainfrom
samikshya-db:samikshya-chand_data/getFunctions

Conversation

@samikshya-db
Copy link
Copy Markdown
Collaborator

@samikshya-db samikshya-db commented Sep 2, 2025

Description

Testing

  • Manually tested using the flag
    String jdbcUrl =
        "jdbc:databricks://<host>;AuthMech=3;httpPath=<httpPath>;EnableShowCommandForGetFunctions=1;";
    ResultSet rs = con.getMetaData().getFunctions("ml_upstart_test", "functions", null);
  • Added unit tests ensuring 100% coverage of code that was added in this PR
  • Also tried with EnableDirectResults=0
  • Also tried with EnableArrow=0

Additional Notes to the Reviewer

  • I am not adding a documentation for this flag, until we want to make it default.

NO_CHANGELOG=true

@samikshya-db samikshya-db changed the title Fix getFunctions in SEA + add a workaround for getFunctions in Thrift add a workaround for getFunctions in Thrift Sep 2, 2025
@samikshya-db samikshya-db marked this pull request as ready for review September 2, 2025 18:35
Copy link
Copy Markdown
Collaborator

@jayantsing-db jayantsing-db left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions inline.

Comment on lines +1547 to +1548
functionNamePattern =
"%"; // This is because functionName is a required parameter in thrift flow.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the function name pattern is null, thrift-server automatically treats it as .*/%

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of thrift get function request, it is a required field. We can't get past the null error in the model itself. Hence, adding this.

}
} catch (Exception e) {
LOGGER.error(e, "Unable to fetch functions, returning empty result set");
LOGGER.error(e, "Unable to fetch functions with error {}, returning empty result set", e);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: e is already passed to log statement, any specific need to re-add and stringify it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to log the error too

Unable to fetch functions, returning empty result set java.lang.NullPointerException: Cannot invoke "com.databricks.jdbc.api.internal.IDatabricksStatementInternal.getStatementId()" because "parentStatement" is null

inplace of

2025-09-10 19:31:37 SEVERE com.databricks.jdbc.api.impl.DatabricksDatabaseMetaData#getFunctions - Unable to fetch functions, returning empty result set

Comment on lines +1638 to +1647
Statement internalStatement = connection.createStatement();
String showFunctionsSqlCommand =
new CommandBuilder(catalog, session)
.setSchemaPattern(schemaPattern)
.setFunctionPattern(functionNamePattern)
.getSQLString(LIST_FUNCTIONS);
DatabricksResultSet rs =
(DatabricksResultSet) internalStatement.executeQuery(showFunctionsSqlCommand);
return new MetadataResultSetBuilder(connection.getConnectionContext())
.getFunctionsResult(rs, catalog);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use iDatabrickClient#executeStatement directly as it is an internal impl detail? This may save us from creating a full statement object and then closing the statement object.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Done.

Comment thread src/main/java/com/databricks/jdbc/api/impl/DatabricksDatabaseMetaData.java Outdated
Comment thread src/main/java/com/databricks/jdbc/dbclient/impl/common/CommandConstants.java Outdated
@samikshya-db samikshya-db merged commit fcfa625 into databricks:main Sep 11, 2025
12 of 13 checks passed
@samikshya-db samikshya-db deleted the samikshya-chand_data/getFunctions branch September 11, 2025 03:13
samikshya-db added a commit that referenced this pull request Sep 25, 2025
## Description
- This issue was uncovered as part of bug raised in #958. Although the
issue was resolved as part of PR #979 - the cause is deeper than that -
TCLIService.client causes state leakage in case previous server call
- This PR fixes the issue.
- Internal doc on root-cause and analysis:
https://docs.google.com/document/d/12kciNIqy-kL1e0HOQs9JOjJlb2zWeNFl02e9kO772PE/edit?tab=t.0

## Testing
- Reset code before [this
commit](fcfa625)
where we fixed getFunctions, and the following code no longer throws
error

```
for (int i = 0; i < 10; i++) {
      try {
        DatabaseMetaData metaData = con.getMetaData();
        metaData.getFunctions("main", "testschema", null).close(); // Metadata call

        Statement stmt = con.createStatement();
        stmt.execute("select * from samikshyachand.default.hello_table"); // SQL query
        stmt.close();

        Thread.sleep(100); // Add a small delay
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
```

## Additional Notes to the Reviewer
<!-- Share any additional context or insights that may help the reviewer
understand the changes better. This could include challenges faced,
limitations, or compromises made during the development process.
Also, mention any areas of the code that you would like the reviewer to
focus on specifically. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] - OSS driver returns empty Resultset from DatabaseMetadata.getFunctions

3 participants